package com.nxbw.quality.application.controller;

import com.nxbw.quality.application.pojo.dto.ApplicationQuery;
import com.nxbw.quality.application.pojo.dto.ApplicationSaveParam;
import com.nxbw.quality.application.service.ApplicationService;
import com.nxbw.quality.base.response.JsonResult;
import com.nxbw.quality.base.response.PageData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/v1/quality/application")
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;

    @RequestMapping("/select")
    public JsonResult selectApplication(ApplicationQuery applicationQuery) {
        log.debug("查询申请: {}",applicationQuery);
        PageData pageData = applicationService.selectApplication(applicationQuery);
        return JsonResult.ok(pageData);
    }

    @PostMapping("/save")
    public JsonResult saveApplication(ApplicationSaveParam applicationSaveParam) {
        log.debug("保存申请: {}",applicationSaveParam);
        applicationService.saveApplication(applicationSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteApplication(@PathVariable Integer id) {
        log.debug("删除申请: {}",id);
        applicationService.deleteApplication(id);
        return JsonResult.ok();
    }

}
